package com.spzx.product.controller;

import com.spzx.common.core.web.controller.BaseController;
import com.spzx.common.core.web.domain.AjaxResult;
import com.spzx.common.core.web.page.TableDataInfo;
import com.spzx.product.domain.CategoryBrand;
import com.spzx.product.domain.CategoryBrandVo;
import com.spzx.product.service.CategoryBrandService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("/categoryBrand")
@Tag(name = "分类品牌接口管理")
public class CategoryBrandController extends BaseController {

    @Autowired
    CategoryBrandService categoryBrandService;


    @Operation(summary = "查询所有分类品牌列表")
    @GetMapping()
    public AjaxResult listAll(){
      return success(categoryBrandService.list());
    }


    @Operation(summary = "查询分类品牌列表")
    @GetMapping("/list")
    public TableDataInfo list(CategoryBrand categoryBrand){
            startPage();
        List<CategoryBrandVo> list=  categoryBrandService.selectCategoryBrandList(categoryBrand);
        return getDataTable(list);
    }

    @Operation(summary = "获取分类品牌详细信息")
    @GetMapping("/{id}")
    public AjaxResult getDetailById(@PathVariable("id") Long id){
       return success(categoryBrandService.getDetailById(id));

    }

    @Operation(summary = "新增分类品牌")
    @PostMapping
    public AjaxResult addCategoryBrand(@Validated @RequestBody CategoryBrand categoryBrand){
        return success(categoryBrandService.addCategoryBrand(categoryBrand));
    }

    @Operation(summary = "修改分类品牌")
    @PutMapping
    public AjaxResult updateCategoryBrand(@Validated @RequestBody CategoryBrand categoryBrand){

        categoryBrandService.updateCategoryBrand(categoryBrand);
        return success(categoryBrandService.updateById(categoryBrand));
    }

    @Operation(summary = "删除分类品牌")
    @DeleteMapping("{ids}")
    public AjaxResult deleteCategoryBrand(@PathVariable Long[] ids){
        return success(categoryBrandService.removeBatchByIds(Arrays.asList(ids)));
    }

    @Operation(summary = "根据分类id获取品牌列表")
    @GetMapping("brandList/{categoryId}")
    public AjaxResult slectListByCategoryId(@PathVariable("categoryId") Long categoryId){
            return success(categoryBrandService.selectBrandById(categoryId));
    }
}
